package f;

import f.f0.c;
import f.f0.d;
import f.x.b;
import java.io.InterruptedIOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

/* compiled from: Dispatcher */
public final class k {
    @Nullable
    public ExecutorService a;
    public final Deque<b> b = new ArrayDeque();
    public final Deque<b> c = new ArrayDeque();
    public final Deque<x> d = new ArrayDeque();

    public k(ExecutorService executorService) {
        this.a = executorService;
    }

    public final <T> void a(Deque<T> deque, T t) {
        int size;
        Object obj;
        synchronized (this) {
            if (deque.remove(t)) {
            } else {
                throw new AssertionError("Call wasn't in-flight!");
            }
        }
        ArrayList arrayList = new ArrayList();
        synchronized (this) {
            Iterator it = this.b.iterator();
            while (it.hasNext()) {
                b bVar = (b) it.next();
                if (this.c.size() >= 64) {
                    break;
                }
                Iterator it2 = this.c.iterator();
                if (it2.hasNext()) {
                    Objects.requireNonNull((b) it2.next());
                    throw null;
                }
                it.remove();
                arrayList.add(bVar);
                this.c.add(bVar);
            }
            synchronized (this) {
                size = this.c.size() + this.d.size();
            }
        }
        if (size > 0) {
        }
        int size2 = arrayList.size();
        int i = 0;
        while (i < size2) {
            ExecutorService executorService;
            b bVar2 = (b) arrayList.get(i);
            synchronized (this) {
                if (this.a == null) {
                    TimeUnit timeUnit = TimeUnit.SECONDS;
                    SynchronousQueue synchronousQueue = new SynchronousQueue();
                    byte[] bArr = c.a;
                    this.a = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, timeUnit, synchronousQueue, new d("OkHttp Dispatcher", false));
                }
                executorService = this.a;
            }
            Objects.requireNonNull(bVar2);
            try {
                executorService.execute(bVar2);
                i++;
            } catch (RejectedExecutionException e) {
                new InterruptedIOException("executor rejected").initCause(e);
                obj = null;
                throw null;
            } catch (Throwable unused) {
            }
        }
        return;
        throw obj;
    }
}
